<?php

namespace app\api\controller\minishop;

use app\common\controller\Api;
use Think\Db;
use app\admin\model\minishop\Icongroup;
use app\admin\model\minishop\Notices;
use app\admin\model\User as userModel;

/**
 * 首页接口
 */
class Index extends Api
{

     // 无需登录的接口,*表示全部
     protected $noNeedLogin = ['getIcongroup','getNotices'];
     // 无需鉴权的接口,*表示全部
     protected $noNeedRight = ['*'];

   

     
    public function getIcongroup()
    {
        // 获取所有导航图标和名称
        $banners = Icongroup::all();
        foreach($banners as &$v){
            $v['icon_image'] = $this->request->domain().$v['icon_image'];
        }
        $this->success('请求成功', $banners);
    }

    public function getNotices()
    {

        $notice_type = $this->request->post("notice_type"); 
        $notices = Notices::select();
        $data = array_column($notices, 'content');
        // if($notice_type==1){
            // 将数组合并为一个字符串，以分号或其他分隔符分隔
            // $data = implode(';', $data);
        // }
        
        $this->success('请求成功', $data);
    }

    public function setRed()
    {
        $money = $this->request->post("money"); 
        $findUser  = userModel::where('id',$this->auth->id)->find();
        if($findUser){
            $money = $this->request->post('money');

            // $result= \app\common\model\User::money($money, $this->auth->id, '领取红包');
            $after = bcadd($findUser['money'],$money,2);
            // 更新用户余额
            $result = userModel::where('id', $this->auth->id)->update(['money' => $after]);

            $this->success('领取成功', $money);
        }else{
            $this->error('找不到该用户');
        }
        
    }
}